package com.kma.ncpractice2013.dao;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author Illyas
 */
public final class Connector
{
	private static DataSource dataSource;
    private static JdbcTemplate template;
    static
    {
        resetJDBCTemplate();
    }
    public static void resetJDBCTemplate()
    {
	    /*ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
	    DataSource dataSource = (DataSource)context.getBean("dataSource");
		*/
	    Context context = null;
	    DataSource ds = null;
	    try
	    {
		    context = new InitialContext();
		    dataSource = (DataSource)context.lookup("jdbc/security");
	    } catch (NamingException e)
	    {
		    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
	    }
	    template = new JdbcTemplate(dataSource);



    }
    public static JdbcTemplate getJDBCTemplate()
    {
        return template;
    }
	public static DataSource getDataSource()
	{
		return dataSource;
	}
}
